package com.mallcloud.mall.mall.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mallcloud.mall.mall.api.entity.XglCouponViewModel;
import com.mallcloud.mall.mall.api.entity.vo.XglCouponViewExcelVO;
import com.mallcloud.mall.mall.api.entity.vo.XglCouponViewVO;
import com.mallcloud.mall.mall.mapper.XglCouponViewMapper;
import com.mallcloud.mall.mall.service.XglCouponViewService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  星光里券
 */
@Service
public class XglCouponViewServiceImpl extends ServiceImpl<XglCouponViewMapper, XglCouponViewModel> implements XglCouponViewService {

	@Override
	public Page<XglCouponViewVO> pageXglCoupon(Page page, XglCouponViewModel param) {
		Page<XglCouponViewVO> resultPage = this.baseMapper.pageXglCoupon(page, param);
		resultPage.getRecords().forEach(x -> x.setTempId(String.format("%s,%s", x.getType(), x.getScheduleId())));
		return resultPage;
	}

	@Override
	public List<XglCouponViewVO> listXglCoupon(XglCouponViewModel param) {
		List<XglCouponViewVO> resultList = this.baseMapper.pageXglCoupon(param);
		resultList.forEach(x -> x.setTempId(String.format("%s,%s", x.getType(), x.getScheduleId())));
		return resultList;
	}

	@Override
	public XglCouponViewVO getInfo(XglCouponViewVO param) {
		XglCouponViewVO info = this.baseMapper.getInfo(param);
		info.setTempId(String.format("%s,%s", info.getType(), info.getScheduleId()));
		return info;
	}

	@Override
	public List<XglCouponViewExcelVO> export(XglCouponViewModel dto) {
		List<XglCouponViewVO> resultList = this.baseMapper.pageXglCoupon(dto);
		return BeanUtil.copyToList(resultList, XglCouponViewExcelVO.class);
	}
}
